<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title></title>
<jsp:include page="../links.jsp"></jsp:include>
</head>
<body>
	<script type="text/javascript">
		var user_datagrid;
		var user_searchForm;
		var user_addDlg;
		var user_addForm;
		var user_updateDlg;
		var user_updateForm;
		$(function() {
			user_datagrid = $('#user_datagrid').datagrid({
				url : getRootPath() + '/admin/userAction/u_datagrid.do',
				title : '用户列表',
				iconCls : 'icon-user',
				pagination : true,
				rownumbers : true,
				selectOnCheck : true,
				checkOnSelect : false,
				pageSize : 10,
				pageList : [ 10, 20, 30, 40, 50 ],
				fit : true,
				fitColumns : true,
				nowarp : false,
				border : false,
				idField : 'uid',
				sortOrder : 'asc',
				columns : [ [ {
					title : '',
					field : 'id',
					width : 100,
					checkbox : true
				}, {
					title : '用户编号',
					field : 'uid',
					width : 100,
					sortable : false
				}, {
					title : '用户密码',
					field : 'pwd',
					width : 200,
				}, {
					title : '真实姓名',
					field : 'realname',
					width : 100,
				}, {
					title : '手机',
					field : 'phone',
					width : 100,
				}, {
					title : 'Email',
					field : 'email',
					width : 150
				}, {
					title : '地址',
					field : 'address',
					width : 200
				} ] ],
				toolbar : [ {
					text : '添加',
					iconCls : 'icon-add',
					handler : function() {
						showAddDlg();
					}
				}, '-', {
					text : '修改',
					iconCls : 'icon-edit',
					handler : function() {
						showUpdateDlg();
					}
				}, '-', {
					text : '删除',
					iconCls : 'icon-remove',
					handler : function() {
						remove();
					}
				} ]
			});//datagrid end
			//过滤查询
			user_searchForm = $('#user_searchForm').form();
			doSearch = function() {
				//console.info(serializeObject(user_searchForm));
				user_datagrid.datagrid('load', serializeObject(user_searchForm));
			};
			//重置
			cleanSearch = function() {
				user_datagrid.datagrid('load', {});
				user_searchForm.find('input').val('');
			};
			//新增
			user_addDlg = $('#user_addDlg').dialog();
			user_addForm = $('#user_addForm').form();
			showAddDlg = function() {
				$('#user_addForm input').val('');
				user_addDlg.dialog('open')
			};
			doAdd = function() {
				user_addForm.form('submit', {
					url : '${pageContext.request.contextPath}/admin/userAction/u_add.do?',
					success : function(data) {
						var r = $.parseJSON(data);
						if (r && r.success) {
							user_addDlg.dialog('close');
							cleanSearch();
							$.messager.show({
								title : '提示',
								msg : r.msg,
								showType : 'show'
							});
						} else {
							$.messager.alert('提示', r.msg);
						}
					}
				});
			};
			//修改
			user_updateDlg = $('#user_updateDlg').dialog();
			user_updateForm = $('#user_updateForm').form();
			showUpdateDlg = function() {
				var selectids = user_datagrid.datagrid('getChecked');
				if (selectids.length == 1) {
					user_updateDlg.dialog('open');
					$('#uid').val(selectids[0].uid);
					//$('#upwd').val(selectids[0].pwd);
					$('#urealname').val(selectids[0].realname);
					$('#uphone').val(selectids[0].phone);
					$('#uemail').val(selectids[0].email);
					//$('#uaddress').val(selectids[0].address);
				} else {
					$.messager.alert('提示', "请勾选一项");
				}
			};
			doUpdate = function() {
				user_updateForm.form('submit', {
					url : '${pageContext.request.contextPath}/admin/userAction/u_update.do?',
					success : function(data) {
						var r = $.parseJSON(data);
						if (r && r.success) {
							user_updateDlg.dialog('close');
							cleanSearch();
							$.messager.show({
								title : '提示',
								msg : r.msg,
								showType : 'show'
							});
						} else {
							$.messager.alert('提示', r.msg);
						}
					}
				});
			};
			//删除
			remove = function() {
				var selectids = user_datagrid.datagrid('getChecked');
				var ids = [];
				if (selectids.length > 0) {
					$.messager.confirm('确认', '您是否要删除当前选中的项目？', function(r) {
						if (r) {
							for (var i = 0; i < selectids.length; i++) {
								ids.push(selectids[i].uid);
							}
							$.ajax({
								url : '${pageContext.request.contextPath}/admin/userAction/u_delete.do',
								data : {
									ids : ids.join(',')
								},
								dataType : 'json',
								success : function(r) {
									user_datagrid.datagrid('load');
									user_datagrid.datagrid('unselectAll');
									$.messager.show({
										title : '提示',
										msg : r.msg
									});
								}
							});
						}
					});
				} else {
					$.messager.alert('提示', "请最少勾选一项");
				}
			};
		});
	</script>
	<div class="easyui-layout" data-options="fit:true,border:false">
		<div data-options="region:'north',title:'模糊查询条件：(右边可折叠)'" style="height: 100%;">
			<form id="user_searchForm" method="post">
				<table style="width: 100%; height: 60%;">
					<tr>
						<th class="th-search-label">用户编号:</th>
						<td><input name="user.uid" maxLength=10 class="easyui-numberbox" type="text" /></td>
						<th class="th-search-label">真实姓名:</th>
						<td><input name="user.realname" /></td>
					</tr>
					<tr>
						<th class="th-search-label">联系电话:</th>
						<td><input name="user.phone" /></td>
						<th class="th-search-label">Email:</th>
						<td><input name="user.email" /></td>
						<td><a class="easyui-linkbutton" style="width: 25%" data-options="iconCls:'icon-search'"
							href="javascript:void(0)" onclick="doSearch();">查询</a>&nbsp;<a class="easyui-linkbutton"
							style="width: 25%" data-options="iconCls:'icon-redo'" href="javascript:void(0)"
							onclick="cleanSearch();">清空</a></td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',title:''," style="overflow: hidden;">
			<table id="user_datagrid">
			</table>
		</div>
		<div id="user_addDlg"
			data-options="closed:true,modal:true,title:'添加用户',buttons:[
				{text : '添加',iconCls : 'icon-add',handler : function() {doAdd();}},
				{text : '取消',iconCls : 'icon-cancel',handler : function() {user_addDlg.dialog('close');}}]"
			class="easyui-dialog" style="width: 270px; height: 230px;" align="center">
			<form id="user_addForm" method="post">
				<table>
					<tr>
						<th>用户编号:</th>
						<td><input name="user.uid" maxLength=10 class="easyui-validatebox" type="number"
							data-options="required:true,validType:['length[0,10]','number'],missingMessage:'请输入10位数字'" value="" /></td>
					</tr>
					<tr>
						<th>用户密码:</th>
						<td><input name="user.pwd" type="password" class="easyui-validatebox" data-options="required:true" /></td>
					</tr>
					<tr>
						<th>真实姓名:</th>
						<td><input name="user.realname" class="easyui-validatebox" data-options="required:true" /></td>
					</tr>
					<tr>
						<th>联系电话:</th>
						<td><input name="user.phone" class="easyui-validatebox" data-options="required:true" /></td>
					</tr>
					<tr>
						<th>Email:</th>
						<td><input name="user.email" class="easyui-validatebox"
							data-options="required:true,validType:'email',missingMessage:'邮箱格式不正确'" /></td>
					<tr>
					<tr>
						<th>联系地址:</th>
						<td><select class="easyui-combobox" name="user.address" style="width: 173px" panelHeight="105px">
								<option value="校本部">校本部</option>
								<option value="旅顺校区一期">旅顺校区一期</option>
								<option value="旅顺校区二期">旅顺校区二期</option>
								<option value="教学南区">教学南区</option>
								<option value="爱恩学院">爱恩学院</option>
						</select></td>
					</tr>
				</table>
			</form>
		</div>
		<div id="user_updateDlg"
			data-options="closed:true,modal:true,title:'修改用户',buttons:[
				{text : '修改',iconCls : 'icon-save',handler : function() {doUpdate();}},
				{text : '取消',iconCls : 'icon-cancel',handler : function() {user_updateDlg.dialog('close');}}]"
			class="easyui-dialog" style="width: 270px; height: 230px;" align="center">
			<form id="user_updateForm" method="post">
				<table>
					<tr>
						<th>用户编号:</th>
						<td><input id="uid" name="user.uid" maxLength=10 class="easyui-validatebox" type="number"
							data-options="required:true,validType:['length[0,10]','number']" value="" /></td>
					</tr>
					<tr>
						<th>用户密码:</th>
						<td><input id="upwd" name="user.pwd" type="password" class="easyui-validatebox"
							data-options="required:true" /></td>
					</tr>
					<tr>
						<th>真实姓名:</th>
						<td><input id="urealname" name="user.realname" class="easyui-validatebox"
							data-options="required:true" /></td>
					</tr>
					<tr>
						<th>联系电话:</th>
						<td><input id="uphone" name="user.phone" class="easyui-validatebox" data-options="required:true" /></td>
					</tr>
					<tr>
						<th>Email:</th>
						<td><input id="uemail" name="user.email" class="easyui-validatebox"
							data-options="required:true,validType:'email',missingMessage:'邮箱格式不正确'" /></td>
					<tr>
					<tr>
						<th>联系地址:</th>
						<td><select id="uaddress" class="easyui-combobox" name="user.address" style="width: 173px"
							panelHeight="105px">
								<option value="校本部">校本部</option>
								<option value="旅顺校区一期">旅顺校区一期</option>
								<option value="旅顺校区二期">旅顺校区二期</option>
								<option value="教学南区">教学南区</option>
								<option value="爱恩学院">爱恩学院</option>
						</select></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</body>
</html>